package com.mark.dao.split;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by Choisaaaa on 2018/4/24.
 *
 */

@Slf4j
public class DynamicDataSourceHolder {
    private static ThreadLocal<String> contextHolder = new ThreadLocal<String>();
    public final  static String DB_MASTER = "master";
    public final  static String DB_SLAVE = "slave";


    //获取线程数据类型
    public static String getDBType(){
        String dbType = contextHolder.get();
        if(dbType == null){
            dbType = DB_MASTER;
        }
        return dbType;
    }

    //设置使用的数据库类型
    public static void setDBType(String dbType){
        log.info("所使用的数据源为：{ "+dbType+" }");
        contextHolder.set(dbType);
    }

    //清理连接池
    public static void clearDBType(){
        contextHolder.remove();
    }
}
